package org.dolphin.service.base;

import java.util.Collection;
import java.util.Locale;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.Assert;

public class CustomAuthenticationToken extends UsernamePasswordAuthenticationToken implements
    CustomAuthentication {
  private static final long serialVersionUID = -8636903123981910785L;
  private Locale locale;
  private String id;

  public CustomAuthenticationToken(String identity, Object principal, Object credentials,
      Locale locale, Collection<? extends GrantedAuthority> authorities) {
    super(principal, credentials, authorities);
    setIdentity(identity);
    setLocale(locale);
  }

  @Override
  public String getIdentity() {
    return id;
  }

  @Override
  public Locale getLocale() {
    return locale;
  }

  @Override
  public void setIdentity(String id) {
    Assert.notNull(id, "Identity is mandatory");
    this.id = id;
  }

  @Override
  public void setLocale(Locale locale) {
    Assert.notNull(locale, "Locale is mandatory");
    this.locale = locale;
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append(super.toString()).append(": ");
    sb.append("Locale: ").append(getLocale()).append("; ");
    return sb.toString();
  }
}
